1 Showcasing RRPlots

1.0.1 Libraries

library(survival)
library(FRESA.CAD)
## Loading required package: Rcpp
## Loading required package: stringr
## Loading required package: miscTools
## Loading required package: Hmisc
## 
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
## 
##     format.pval, units
## Loading required package: pROC
## Type 'citation("pROC")' for a citation.
## 
## Attaching package: 'pROC'
## The following objects are masked from 'package:stats':
## 
##     cov, smooth, var
#source("~/GitHub/FRESA.CAD/R/RRPlot.R")
#source("~/GitHub/FRESA.CAD/R/PoissonEventRiskCalibration.R")
op <- par(no.readonly = TRUE)
pander::panderOptions('digits', 3)
#pander::panderOptions('table.split.table', 400)
pander::panderOptions('keep.trailing.zeros',TRUE)
layout(matrix(1:1, nrow=1))

1.0.2 Wisconsin Data Set

dataBreast <- read.csv("~/GitHub/RISKPLOTS/DATA/wpbc.data", header=FALSE)
table(dataBreast$V2)
## 
##   N   R 
## 151  47
rownames(dataBreast) <- dataBreast$V1
dataBreast$V1 <- NULL
dataBreast$status <- 1*(dataBreast$V2=="R")
dataBreast$V2 <- NULL
dataBreast$time <- dataBreast$V3
dataBreast$V3 <- NULL
dataBreast <- sapply(dataBreast,as.numeric)
## Warning in lapply(X = X, FUN = FUN, ...): NAs introduced by coercion
dataBreast <- as.data.frame(dataBreast[complete.cases(dataBreast),])
table(dataBreast$status)
## 
##   0   1 
## 148  46

1.1 Exploring Raw Features with RRPlot

convar <- colnames(dataBreast)[lapply(apply(dataBreast,2,unique),length) > 10]
convar <- convar[convar != "time"]
topvar <- univariate_BinEnsemble(dataBreast[,c("status",convar)],"status")
pander::pander(topvar)
V35 V24 V34 V7 V16 V14 V17
0.0261 0.0261 0.0261 0.0623 0.126 0.126 0.126
topv <- min(5,length(topvar))
topFive <- names(topvar)[1:topv]
RRanalysis <- list();
idx <- 1
topf <- topFive[1]
for (topf in topFive)
{
  RRanalysis[[idx]] <- RRPlot(cbind(dataBreast$status,dataBreast[,topf]),
                              atRate=c(0.90,0.80),
                  timetoEvent=dataBreast$time,
                  title=topf,
#                  plotRR=FALSE
                  )
  idx <- idx + 1
}

names(RRanalysis) <- topFive

1.2 Reporting the Metrics

pander::pander(RRanalysis[[1]]$keyPoints,caption=topFive[1])
V35
  Thr RR RR_LCI RR_UCI SEN SPE BACC
@:0.9 1.00e+01 1.57 0.8370 2.93 0.174 0.8986 0.536
@:0.8 3.00e+00 2.32 1.4235 3.77 0.478 0.7770 0.628
@MAX_BACC 9.73e-09 3.07 1.5720 6.01 0.804 0.5000 0.652
@MAX_RR 7.92e-09 3.19 1.5760 6.47 0.826 0.4730 0.650
@SPE100 -9.00e-09 7.23 0.0162 3218.44 1.000 0.0203 0.510
pander::pander(RRanalysis[[2]]$keyPoints,caption=topFive[2])
V24
  Thr RR RR_LCI RR_UCI SEN SPE BACC
@:0.9 25.4 1.94 1.1306 3.34 0.239 0.8919 0.566
@:0.8 23.9 1.67 1.0015 2.78 0.348 0.7905 0.569
@MAX_BACC 20.3 2.45 1.3530 4.44 0.739 0.5270 0.633
@MAX_RR 16.6 3.87 0.9914 15.08 0.957 0.1824 0.569
@SPE100 15.5 33.04 0.0685 15945.00 1.000 0.0878 0.544
RRanalysis[[2]]$keyPoints["@MAX_BACC",c("BACC","RR")]
           BACC       RR

@MAX_BACC 0.6330787 2.451923

ROCAUC <- NULL
CstatCI <- NULL
LogRangp <- NULL
Sensitivity <- NULL
Specificity <- NULL
MAXBACC <- NULL
RREst <- NULL

for (topf in topFive)
{
  CstatCI <- rbind(CstatCI,RRanalysis[[topf]]$c.index$cstatCI)
  LogRangp <- rbind(LogRangp,RRanalysis[[topf]]$surdif$pvalue)
  Sensitivity <- rbind(Sensitivity,RRanalysis[[topf]]$ROCAnalysis$sensitivity)
  Specificity <- rbind(Specificity,RRanalysis[[topf]]$ROCAnalysis$specificity)
  ROCAUC <- rbind(ROCAUC,RRanalysis[[topf]]$ROCAnalysis$aucs)
  MAXBACC <- rbind(MAXBACC,RRanalysis[[topf]]$keyPoints["@MAX_BACC",c("BACC")])
  RREst <- rbind(RREst,RRanalysis[[topf]]$keyPoints[1,c("RR")])
}
rownames(CstatCI) <- topFive
rownames(LogRangp) <- topFive
rownames(Sensitivity) <- topFive
rownames(Specificity) <- topFive
rownames(ROCAUC) <- topFive
rownames(MAXBACC) <- topFive
rownames(RREst) <- topFive

pander::pander(ROCAUC)
  est lower upper
V35 0.660 0.569 0.751
V24 0.633 0.542 0.724
V34 0.656 0.570 0.743
V7 0.610 0.515 0.705
V16 0.598 0.504 0.692
pander::pander(CstatCI)
  mean.C Index median lower upper
V35 0.641 0.642 0.551 0.726
V24 0.677 0.675 0.597 0.750
V34 0.654 0.655 0.584 0.722
V7 0.666 0.666 0.583 0.745
V16 0.614 0.617 0.531 0.700
pander::pander(LogRangp)
V35 0.00104
V24 0.00938
V34 0.00282
V7 0.07332
V16 0.02135
pander::pander(Sensitivity)
  est lower upper
V35 0.152 0.0634 0.289
V24 0.239 0.1259 0.388
V34 0.152 0.0634 0.289
V7 0.152 0.0634 0.289
V16 0.109 0.0362 0.236
pander::pander(Specificity)
  est lower upper
V35 0.899 0.838 0.942
V24 0.899 0.838 0.942
V34 0.892 0.830 0.937
V7 0.899 0.838 0.942
V16 0.899 0.838 0.942
pander::pander(MAXBACC)
V35 0.652
V24 0.633
V34 0.645
V7 0.621
V16 0.614
pander::pander(RREst)
V35 1.57
V24 1.94
V34 1.33
V7 1.33
V16 1.00
meanMatrix <- cbind(ROCAUC[,1],CstatCI[,1],RREst,Sensitivity[,1],Specificity[,1],MAXBACC)
colnames(meanMatrix) <- c("ROCAUC","C-Stat","RR","Sen","Spe","MAX_BACC")
pander::pander(meanMatrix)
  ROCAUC C-Stat RR Sen Spe MAX_BACC
V35 0.660 0.641 1.57 0.152 0.899 0.652
V24 0.633 0.677 1.94 0.239 0.899 0.633
V34 0.656 0.654 1.33 0.152 0.892 0.645
V7 0.610 0.666 1.33 0.152 0.899 0.621
V16 0.598 0.614 1.00 0.109 0.899 0.614

1.3 Modeling

ml <- BSWiMS.model(Surv(time,status)~1,data=dataBreast,NumberofRepeats = 10)

[+++++++++++++++++++++++++++++++++++++++++++++++++++]…..

sm <- summary(ml)
pander::pander(sm$coefficients)
Table continues below
  Estimate lower HR upper u.Accuracy r.Accuracy
V24 4.79e-02 1.01 1.05 1.08 0.598 0.241
V27 2.71e-04 1.00 1.00 1.00 0.608 0.237
V26 3.90e-03 1.00 1.00 1.01 0.593 0.392
V34 1.27e-02 1.00 1.01 1.02 0.634 0.257
V7 4.75e-08 1.00 1.00 1.00 0.588 0.237
V35 3.71e-03 1.00 1.00 1.01 0.727 0.593
V4 9.36e-07 1.00 1.00 1.00 0.582 0.237
Table continues below
  full.Accuracy u.AUC r.AUC full.AUC IDI NRI z.IDI
V24 0.598 0.609 0.501 0.609 0.0618 0.435 2.86
V27 0.608 0.608 0.500 0.608 0.0563 0.434 2.76
V26 0.601 0.598 0.545 0.604 0.0622 0.403 2.75
V34 0.632 0.618 0.506 0.618 0.0315 0.468 2.40
V7 0.588 0.595 0.500 0.595 0.0487 0.380 2.30
V35 0.619 0.641 0.598 0.615 0.0275 0.551 2.24
V4 0.582 0.606 0.500 0.606 0.0449 0.426 2.19
  z.NRI Delta.AUC Frequency
V24 2.66 0.1079 1.0
V27 2.63 0.1084 1.0
V26 2.44 0.0589 1.0
V34 2.83 0.1115 1.0
V7 2.30 0.0949 0.7
V35 3.41 0.0170 0.9
V4 2.62 0.1065 0.1

1.4 Cox Model Performance

Here we evaluate the model using the RRPlot() function.

1.4.1 The evaluation of the raw Cox model with RRPlot()

Here we will use the predicted event probability assuming a baseline hazard for events withing 5 years

index <- predict(ml,dataBreast)
timeinterval <- 2*mean(subset(dataBreast,status==1)$time)

h0 <- sum(dataBreast$status & dataBreast$time <= timeinterval)
h0 <- h0/sum((dataBreast$time > timeinterval) | (dataBreast$status==1))
pander::pander(t(c(h0=h0,timeinterval=timeinterval)),caption="Initial Parameters")
Initial Parameters
h0 timeinterval
0.323 51.1
rdata <- cbind(dataBreast$status,ppoisGzero(index,h0))
rownames(rdata) <- rownames(dataBreast)

rrAnalysisTrain <- RRPlot(rdata,atRate=c(0.90,0.80),
                     timetoEvent=dataBreast$time,
                     title="Raw Train: Breast Cancer",
                     ysurvlim=c(0.00,1.0),
                     riskTimeInterval=timeinterval)

1.4.2 Uncalibrated Performance Report

pander::pander(t(rrAnalysisTrain$keyPoints),caption="Threshold values")
Threshold values
  @:0.9 @:0.8 @MAX_BACC @MAX_RR @SPE100 p(0.5)
Thr 0.42409 0.3578 0.2516 0.1792 1.63e-01 5.00e-01
RR 1.94392 1.8335 2.4016 3.5569 2.77e+01 2.27e+00
RR_LCI 1.13060 1.1114 1.3254 0.9152 5.75e-02 1.21e+00
RR_UCI 3.34229 3.0246 4.3518 13.8238 1.33e+04 4.27e+00
SEN 0.23913 0.3696 0.7391 0.9565 1.00e+00 1.30e-01
SPE 0.89189 0.7973 0.5203 0.1689 7.43e-02 9.59e-01
BACC 0.56551 0.5834 0.6297 0.5627 5.37e-01 5.45e-01
NetBenefit -0.00402 0.0015 0.0522 0.0884 9.97e-02 -4.27e-05
pander::pander(t(rrAnalysisTrain$OERatio$estimate),caption="O/E Test")
O/E Test
O/E Low Upper p.value
0.845 0.618 1.13 0.278
pander::pander(t(rrAnalysisTrain$OE95ci),caption="O/E Mean")
O/E Mean
mean 50% 2.5% 97.5%
1.02 1.02 0.972 1.08
pander::pander(t(rrAnalysisTrain$OARatio$estimate),caption="O/Acum Test")
O/Acum Test
O/A Low Upper p.value
0.811 0.594 1.08 0.163
pander::pander(t(rrAnalysisTrain$OAcum95ci),caption="O/Acum Mean")
O/Acum Mean
mean 50% 2.5% 97.5%
0.799 0.799 0.793 0.805
pander::pander(t(rrAnalysisTrain$c.index$cstatCI),caption="C. Index")
C. Index
mean.C Index median lower upper
0.683 0.683 0.602 0.758
pander::pander(t(rrAnalysisTrain$ROCAnalysis$aucs),caption="ROC AUC")
ROC AUC
est lower upper
0.642 0.551 0.733
pander::pander((rrAnalysisTrain$ROCAnalysis$sensitivity),caption="Sensitivity")
Sensitivity
est lower upper
0.239 0.126 0.388
pander::pander((rrAnalysisTrain$ROCAnalysis$specificity),caption="Specificity")
Specificity
est lower upper
0.899 0.838 0.942
pander::pander(t(rrAnalysisTrain$thr_atP),caption="Probability Thresholds")
Probability Thresholds
90% 80%
0.425 0.357
pander::pander(rrAnalysisTrain$surdif,caption="Logrank test")
Logrank test Chisq = 11.354656 on 2 degrees of freedom, p = 0.003423
  N Observed Expected (O-E)^2/E (O-E)^2/V
class=0 147 29 36.99 1.725 8.974
class=1 21 6 4.41 0.573 0.643
class=2 26 11 4.60 8.896 9.982